package cn.minimelon.cushaw.impl;

import cn.minimelon.bittermelon.bean.BaseMap;
import cn.minimelon.bittermelon.utils.JSONUtils;
import cn.minimelon.bittermelon.utils.Melon;
import cn.minimelon.cushaw.entity.SysFields;
import cn.minimelon.cushaw.service.SysFieldsService;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.query.LambdaQuery;
import org.noear.solon.annotation.Inject;
import org.noear.solon.extend.aspect.annotation.Service;

import java.util.List;

@Service
public class SysFieldsServiceImpl implements SysFieldsService {
    @Inject
    SQLManager sqlManager;

    @Override
    public List<SysFields> selectByDefCode(String defCode) {
        LambdaQuery<SysFields> query = sqlManager.lambdaQuery(SysFields.class);
        List<SysFields> list = query.andEq(SysFields::getDefCode, defCode).select();
        for (SysFields f : list) {
            if (Melon.isNotEmpty(f.getSwitchs())) {
                f.setSw(JSONUtils.parseObject(f.getSwitchs(), BaseMap.class));
            }
            if (Melon.isNotEmpty(f.getMore())) {
                f.setMo(JSONUtils.parseObject(f.getMore(), BaseMap.class));
            }
        }
        return list;
    }
}
